﻿<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>RBAC-CLI - 角色列表</title>
    <meta name="keywords" content="RBAC,CLI,权限,权限脚手架">
    <meta name="description" content="一款基于Spring+SpringMVC+Mybatis+Shiro的一个权限脚手架，用户可在此基础上很方便的进行二次开发！">
    <!--浏览器默认内核指定-->
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <!--指定IE8浏览器去模拟某个特定版本的IE浏览器的渲染方式-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <!--设置移动端自适应-->
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <!--禁止搜索引擎转码-->
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--在浏览器收藏夹中显示的图标-->
    <link rel="Bookmark" href="/resources/favicon.ico">
    <!--网页标题小图标-->
    <link rel="Shortcut Icon" href="/resources/favicon.ico"/>
    <!--css引入-->
    <link rel="stylesheet" type="text/css" href="/resources/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/resources/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="/resources/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="/resources/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="/resources/static/h-ui.admin/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="/resources/lib/jquery.bsgrid-1.37/builds/merged/bsgrid.all.min.css"/>
    <style>
        table.bsgrid{width:100%;}
    </style>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/resources/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/resources/lib/respond.min.js"></script>
    <![endif]-->
    <!--[if IE 6]>
    <script type="text/javascript" src="/resources/lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span> 角色权限管理
    <span class="c-gray en">&gt;</span> 角色管理
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            <a href="javascript:;" onclick="batchDel()" class="btn btn-danger radius">
                <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
            </a>
            <a class="btn btn-primary radius" href="javascript:;" onclick="addRole()">
                <i class="Hui-iconfont">&#xe600;</i> 添加角色
            </a>
        </span>
        <span class="r">共有数据：<strong id="totalRows"></strong> 条</span>
    </div>
    <table id="bsGrid" class="bsgrid">
        <tr>
            <th w_index="id" w_check="true"></th>
            <th w_index="id">ID</th>
            <th w_index="name" w_render="nameFmt">角色名称</th>
            <th w_index="remarks">备注</th>
            <th w_index="reallyName">创建者</th>
            <th w_index="createTime" w_render="createTimeFmt">创建时间</th>
            <th w_render="toolbar" w_align="center">工具栏</th>
        </tr>
    </table>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/resources/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/resources/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/resources/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/resources/static/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/resources/lib/jquery.bsgrid-1.37/builds/js/lang/grid.zh-CN.min.js"></script>
<script type="text/javascript" src="/resources/lib/jquery.bsgrid-1.37/builds/merged/bsgrid.all.min.js"></script>
<script type="text/javascript">
    var gridObj;
    $(function () {
        // 初始化表格
        gridObj = $.fn.bsgrid.init('bsGrid', {
            url: '/sys/role/list',
            pageSizeSelect: true,
            pageSize: 20,
            rowHoverColor: true,
            complete: function () {
                $("#totalRows").text(gridObj.getTotalRows());
            }
        });
    });

    // 工具栏
    function toolbar(row) {
        var id = row.id;
        var html = "";
        html += '<a title="编辑" href="javascript:;" onclick="editRole(\'' + id + '\')" class="ml-15"><i class="Hui-iconfont">&#xe6df;</i>编辑</a>';
        html += '<a title="删除" href="javascript:;" onclick="delRole(\'' + id + '\')" class="ml-15"><i class="Hui-iconfont">&#xe6e2;</i>删除</a>';
        return html;
    }

    // 角色名称格式化
    function nameFmt(row) {
        return "<span class='label label-secondary radius'>" + row.name + "</span>";
    }

    // 格式化创建时间
    function createTimeFmt(row) {
        return (new Date(row.createTime)).Format("yyyy-MM-dd hh:mm:ss");
    }

    // 添加角色
    function addRole() {
        layer.open({
            title: '添加角色',
            type: 2,
            shade: false,
            maxmin: true,
            shade: 0.5,
            area: ['80%', '80%'],
            content: '/sys/role/add',
            zIndex: layer.zIndex,
            end: function () {
                gridObj.refreshPage();
            }
        });
    }

    // 编辑角色
    function editRole(id) {
        layer.open({
            title: '编辑角色',
            type: 2,
            shade: false,
            maxmin: true,
            shade: 0.5,
            area: ['80%', '80%'],
            content: '/sys/role/edit/' + id,
            zIndex: layer.zIndex,
            end: function () {
                gridObj.refreshPage();
            }
        });
    }

    // 批量删除角色
    var loadIndex;
    function batchDel() {
        var ids = gridObj.getCheckedValues('id');
        if (ids.length == 0) {
            layer.msg('未勾选有效数据', {icon: 5, time: 1000});
            return;
        }
        layer.confirm('确认要删除吗？', {icon: 3, title: '提示'}, function (index) {
            $.ajax({
                type: 'post',
                url: '/sys/role/batchDel',
                dataType: 'json',
                data: {'ids': ids.toString()},
                beforeSend: function () {
                    layer.close(index);
                    loadIndex = layer.load(0, {shade: 0.1});
                },
                complete: function () {
                    layer.close(loadIndex);
                    gridObj.refreshPage();
                },
                success: function (data) {
                    if (data.status == 0) {
                        layer.msg(data.msg, {icon: 1, time: 1000});
                    } else {
                        layer.msg(data.msg, {icon: 5, time: 1000});
                    }
                },
                error: function () {
                    layer.msg('服务器错误', {icon: 5, time: 1000});
                }
            });
        });
    }

    // 删除单条角色
    function delRole(id) {
        layer.confirm('确认要删除吗？', {icon: 3, title: '提示'}, function (index) {
            $.ajax({
                type: 'post',
                url: '/sys/role/batchDel',
                dataType: 'json',
                data: {'ids': id},
                beforeSend: function () {
                    layer.close(index);
                    loadIndex = layer.load(0, {shade: 0.1});
                },
                complete: function () {
                    layer.close(loadIndex);
                    gridObj.refreshPage();
                },
                success: function (data) {
                    if (data.status == 0) {
                        layer.msg('删除成功', {icon: 1, time: 1000});
                    } else {
                        layer.msg(data.msg, {icon: 5, time: 1000});
                    }
                },
                error: function () {
                    layer.msg('服务器错误', {icon: 5, time: 1000});
                }
            });
        });
    }

    // 时间格式化Util
    Date.prototype.Format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            }
        }
        return fmt;
    }
</script>
</body>
</html>